# $Id: PKGBUILD 175505 2013-01-17 15:01:31Z tpowa $
# Maintainer: Tobias Powalowski <tpowa@archlinux.org>

pkgbase='ocaml'
pkgname=('ocaml' 'ocaml-compiler-libs')
pkgver=4.00.1
pkgrel=3
pkgdesc="A functional language with OO extensions"
arch=('i686' 'x86_64')
license=('LGPL2' 'custom: QPL-1.0')
url="http://caml.inria.fr/"
depends=('gdbm')
makedepends=('tk>=8.6.0' 'ncurses>=5.6-7' 'libx11')
optdepends=('ncurses: advanced ncurses features' 'tk: advanced tk features')
source=(http://caml.inria.fr/distrib/ocaml-4.00/${pkgname}-${pkgver}.tar.gz
        tk8.6-build.patch)
options=('!makeflags' '!emptydirs')

build() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  ./configure -prefix /usr 
  make world.opt
}

package_ocaml() {
  cd "${srcdir}/${pkgbase}-${pkgver}"
  # fix https://bugs.archlinux.org/task/33302
  patch -Np2 -i ../tk8.6-build.patch
  make PREFIX="${pkgdir}/usr" MANDIR="${pkgdir}/usr/share/man" install
   
  # Save >10MB with this one, makepkg only strips debug symbols.
  #find "${pkgdir}/usr/lib" -type f -name '*.so.*' -exec strip --strip-unneeded {} \;

  # install license
  install -m755 -d "${pkgdir}/usr/share/licenses/${pkgname}"
  install -m644 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/"
}

package_ocaml-compiler-libs() {
pkgdesc="Several modules used internally by the OCaml compiler"
license=('custom: QPL-1.0')
depends=('ocaml')
optdepends=()

  cd "${srcdir}/${pkgbase}-${pkgver}"

  # Install compiler libraries
  local compiler_libs="${pkgdir}/usr/lib/ocaml/compiler-libs"
  mkdir -p "$compiler_libs"/{parsing,typing,utils}
  cp parsing/*.{cmi,cmo,cmx,ml,mli,mll,o} "$compiler_libs"/parsing
  cp typing/*.{cmi,cmo,cmx,ml,mli,o} "$compiler_libs"/typing
  cp utils/*.{cmi,cmo,cmx,ml,mli,o} "$compiler_libs"/utils
  # duplicated by installation
  rm -f "$compiler_libs"/typing/outcometree.{cmi,mli}

  # install license
  install -m755 -d "${pkgdir}/usr/share/licenses/${pkgname}"
  install -m644 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/"
}
md5sums=('91124a8eb12a57f1e56c02fe3db0f9e7')
md5sums=('91124a8eb12a57f1e56c02fe3db0f9e7'
         '67b0a8a8885fc1221181b171541cb1b0')
